﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CE.HR;

public partial class HR_change_password : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.HRId] == null)
        {
            Response.Redirect("login.aspx");
        }
    }
    protected void btnSubmitForm_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            Int64 _hrid = Int64.Parse(Session[CE.Global.General.HRId].ToString());

            HRAccount _account = new HRAccount();
            HRAccountDB _accountdb = new HRAccountDB();
            _account = _accountdb.GetAccount(_hrid);
            if (txtCurPassword.Text == _account.AuthCode)
            {
                _account.AuthCode = txtNewPassword.Text;

                if (_accountdb.InsertUpdate(_account) > 0)
                {
                    lblMessage.Text = "Update completed.";
                    lblMessage.ForeColor = System.Drawing.Color.Green;
                }
                else
                {
                    lblMessage.Text = "Change password failed!Try again later!";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
            }
            else
            {
                lblMessage.Text = "Old password is wrong.";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
    }
}
